#!/bin/bash

# File: hooks
# This is called by startuphook in xmonad.hs with "autostart" argument

# Run the program if it is not already running
# checkandstart <program_name> <delay in starting> <program options string>
function checkandstart()
{
    # run if the program $1 is not running
    if pgrep -u $USER -f $1 >/dev/null
    then
        echo $1 already running
    else
        sleep $2 && $1 $3 &
    fi
}

# This is the actual startup program
function startup()
{
    ~/bin/switch_keyboard_layout_colemak.sh &
    ~/bin/have_a_break.sh &
    nitrogen --restore &
    xsetroot -cursor_name left_ptr &
    xset b off & # remove console beeps while running X 

    checkandstart stalonetray 0 

    # not-tray applications
    checkandstart bbpager 0
    checkandstart conky 0
#    checkandstart halevt 0 
    checkandstart lineakd 0 
    checkandstart mpd 0
    checkandstart mpn 0
    checkandstart vym 0
    checkandstart xscreensaver 0 "-no-splash"
    checkandstart ~/bin/dzen_v_clock.sh 0
    checkandstart unclutter 0 "-visible -grab"

    # tray applications
    checkandstart xfce4-power-manager 1 # should be the first one
    checkandstart blueman-applet 1
    checkandstart pidgin 1
    checkandstart ganyremote 1
    checkandstart gmusicbrowser 1
    checkandstart goldendict 1
    checkandstart osmo 1
    checkandstart padevchooser 1
    checkandstart wicd-client 1

    return
}

# This is the main entry point of script
if [ $1 = "autostart" ]
then
    startup &
fi
return

